<!--!
This file is a part of MediaDrop (https://www.mediadrop.video),
Copyright 2009-2018 MediaDrop contributors
For the exact contribution history, see the git revision log.
The source code contained in this file is licensed under the GPLv3 or
(at your option) any later version.
See LICENSE.txt in the main project directory, for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="../master.html" />
<head>
	<title>${media.title and _('Edit') + ': ' + media.title or _('Add New Media')}</title>
	<link href="${h.url_for('/admin/styles/forms.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/datepicker.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/uploader.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/media.css')}" media="screen" rel="stylesheet" type="text/css" />
	<py:choose>
		<py:when test="bool(h.request.params.get('debug', False))">
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/DynamicTextarea-0.92.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/Fx.ProgressBar.js')}"></script>
	        <script type="text/javascript" src="/scripts/third-party/Swiff.Uploader.js"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/datepicker.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/meio-mask/Meio.Mask.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/squeezebox-1.1-rc4.js')}"></script>
		</py:when>
		<py:otherwise>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/DynamicTextarea-0.92-yui-compressed.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/Fx.ProgressBar-yui-compressed.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/Swiff.Uploader.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/datepicker.min.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/meio-mask/Meio.Mask.min.js')}"></script>
	        <script type="text/javascript" src="${h.url_for('/scripts/third-party/squeezebox-1.1-rc4-yui-compressed.js')}"></script>
		</py:otherwise>
	</py:choose>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/forms.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/uploader.js')}"></script>
	<link type="text/css" href="${h.url_for('/admin/styles/squeezebox.css')}" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="${h.url_for('/admin/scripts/confirm.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/modals.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/media.js')}"></script>
	<script type="text/javascript">
		// redirect to the actual media page if an id has been provided in the hash
		if (window.location.hash) {
			var id = window.location.hash.substr(1).toInt();
			if (id) {
				var loc = new String(window.location);
				window.location = loc.substr(0, loc.lastIndexOf('new')) + id;
			}
		}
		/* Create the width x height mask */
		Meio.Mask.createMasks('Regexp', {
			'widthxheight': {
				regex: /^(\d+x){0,1}(\d+)?$/
			}
		});
		MooTools.lang.set('en-US', 'FancyUpload', {
			errors: {
				httpStatus: '${_('Saving the file failed. Please try again').replace("'", "\\'")}',
				securityError: '${_('Security error occured (%(text)s)').replace("'", "\\'") % dict(text='{text}')}',
				ioError: '${_('Error caused a send or load operation to fail (%(text)s)').replace("'", "\\'") % dict(text='{text}')}'
			},
			validationErrors: {
				duplicate: '${_('File has already been added, duplicates are not allowed').replace("'", "\\'")}',
				sizeLimitMin: '${_('File is too small, the minimal file size is %(size)s').replace("'", "\\'") % dict(size='{fileSizeMin}')}',
				sizeLimitMax: '${_('File is too large, the maximum file size is %(size)s').replace("'", "\\'") % dict(size='{fileSizeMax}')}',
				fileListMax: '${_('File could not be added, amount of %(num)s files exceeded').replace("'", "\\'") % dict(num='{fileListMax}')}',
				fileListSizeMax: '${_('File is too big, overall filesize of %(size)s exceeded').replace("'", "\\'") % dict(size='{fileListSizeMax}')}'
			}
		});
		var fileMgr, mediaMgr; // Make the fileMgr and mediaMgr 'public'
		window.addEvent('domready', function(){
			var deleteConfirm = new DeleteConfirmMgr({
				header: '${_('Confirm Delete').replace("'", "\\'")}',
				msg: '${_('Are you sure you want to delete this?').replace("'", "\\'")}',
				confirmButtonText: '${_('Delete').replace("'", "\\'")}',
				cancelButtonText: '${_('Cancel').replace("'", "\\'")}'
			});
			/* read only plugin (or any other plugin) might decide to remove 
			 * the delete button, handle a missing button gracefully... */
			var deleteButton = $('delete');
			if (deleteButton)
				deleteButton.addEvent('click', deleteConfirm.openConfirmDialog.bind(deleteConfirm));

			// Setup the flash uploader
			var thumbUploader = new ThumbUploader({
				image: 'thumb-img',
				target: 'thumb',
				statusContainer: 'thumb-upload',
				uploadBtnText: '${_('Upload image').replace("'", "\\'")}',
				fxProgressBar: {url: '${h.url_for('/admin/images/progressbar/progress.png')}'},
				path: '${h.url_for('/scripts/third-party/Swiff.Uploader.swf')}',
				verbose: false // debug
			});

			// Setup the file manager (which hooks into the uploader)
			fileMgr = new FileManager('fmgr', {
				addForm: 'add-file-form',
				deleteConfirmMsg: function(name){ return "${_('Are you sure you want to delete this file?')}\n\n" + name; },
				editURL: '${h.url_for(action='edit_file')}',
				uploader: {
					target: 'file',
					uploadBtn: {'class': 'btn grey f-rgt'},
					uploadBtnText: '${_('Upload a file').replace("'", "\\'")}',
					fxProgressBar: {url: '${h.url_for('/admin/images/progressbar/progress.png')}'},
					path: '${h.url_for('/scripts/third-party/Swiff.Uploader.swf')}',
					fileSizeMax: ${settings['max_upload_size']},
					typeFilter: '*.*',
					verbose: false // debug
				},
				addError: '${_('Failed to add this file. Please try again.').replace("'", "\\'")}',
				saveError: '${_('Failed to save your change. Please try again.').replace("'", "\\'")}',
				uploadingText: '${_('Uploading').replace("'", "\\'")}',
				queuedText: '${_('Queued').replace("'", "\\'")}',
				errorText: '${_('Error').replace("'", "\\'")}'
			});
			$('fmgr-open').addEvent('click', fileMgr.open.bind(fileMgr));
			$('fmgr-close').addEvent('click', fileMgr.close.bind(fileMgr));
			var fileList = new FileList('file-list', fileMgr, {
				statusContainer: $('file-upload'),
				fxProgressBar: {url: '${h.url_for('/admin/images/progressbar/progress.png')}'}
			});

			var publishStatus = new StatusForm({
				form: 'update-status-form',
				error: 'update-status-error',
				connectionErrorText: '${_('A connection problem occurred, try again.').replace("'", "\\'")}',
				genericErrorText: '${_('An error has occurred, try again.').replace("'", "\\'")}'
			});
			var metaForm = new MediaMetaForm('media-form', {
				slug: {editText: '${_('Edit').replace("'", "\\'")}', hideText: '${_('Hide').replace("'", "\\'")}'},
				spinner: {text: '${_('Saving').replace("'", "\\'")}'},
				success: {text: '${_('Saved!').replace("'", "\\'")}'},
				failure: {text: '${_('Saving failed. Please try again.').replace("'", "\\'")}'},
				userError: {text: '${_('Please correct the highlighted errors and save again.').replace("'", "\\'")}'}
			});
			mediaMgr = new MediaManager({
				metaForm: metaForm,
				statusForm: publishStatus,
				files: fileMgr,
				fileUploader: fileMgr.uploader,
				thumbUploader: thumbUploader,
				thumbImg: 'thumb-img',
				isNew: ${int(media.id is None)},
				mergeURL: '${h.url_for(action='merge_stubs', id=None)}',
				type: ${(media.type and "'%s'" % media.type) or 'null'},
				head: 'media-title'
			});
		});
	</script>
</head>
<body id="media-edit" class="menu-media-on">
	<div class="column66">

		<div class="box">
			<div class="box-head">
				<small py:if="media.created_on" class="box-head-sec">Uploaded: ${h.format_date(media.created_on)}</small>
				<h1 id="media-title">${media.title or _('Add New Media')}</h1>
			</div>
			<form py:replace="media_form(media_values, action=media_action, child_args={'categories': {'category_tree': category_tree}})" />
		</div>

	</div>
	<div class="column33">
		<div py:replace="update_status_form(media=media, action=update_status_action)" />

		<div id="media-files-box" class="box">
			<div class="box-head"><h1>Files</h1></div>
			<div class="box-content"><div id="fmgr-open" class="btn block"><span>Add &amp; Manage</span></div></div>
			<ol id="file-list" class="file-list">
				<li py:for="file in media.files" class="${file.type}" id="list-file-${file.id}">
					<a class="file-name" href="${h.best_link_uri(file)}"
					   title="View this file">
					   ${h.wrap_long_words(file.display_name)}
					</a>
				</li>
			</ol>
			<div id="file-upload" class="upload-status">
				<div class="upload-progress hidden">
					<img src="${h.url_for('/admin/images/progressbar/bar.png')}" width="238" height="12" />
				</div>
			</div>
		</div>

		<div class="box">
			<h1 class="box-head">Thumbnail</h1>
			<div class="box-content">
				<div class="thumb" py:with="thumb = h.thumb(media, 'm')">
					<img id="thumb-img" alt="Thumb"
					     src="${thumb.url}" width="${thumb.x}" height="${thumb.y}" />
				</div>
				<div class="center">
					<form py:replace="thumb_form(css_class='center', action=thumb_action)" />
				</div>
			</div>
			<div id="thumb-upload" class="upload-status">
				<div class="upload-file hidden" />
				<div class="upload-progress hidden">
					<img src="${h.url_for('/admin/images/progressbar/bar.png')}" width="238" height="12" />
				</div>
				<div class="box-error upload-error hidden" />
			</div>
		</div>

		<div class="box" py:if="media.id and (settings['comments_engine'] == 'builtin')"
		     py:replace="comment_stats_box(h.url_for(controller='/admin/comments', media_filter=media.id), query=media.comments)" />

	</div>

<div class="hidden">
	<div id="fmgr" class="box box-wide">
		<div class="box-head clearfix">
			<h1>Manage Files</h1>
			<div class="box-head-sec">
				${h.doc_link('admin/media', 'edit')} |
				<span id="fmgr-close" class="clickable">Hide</span>
			</div>
		</div>
		<table class="box-content" cellspacing="0" cellpadding="0">
			<thead>
				<tr>
					<th id="thf-name">File</th>
					<th id="thf-size">Size</th>
					<th id="thf-duration">Duration</th>
					<th id="thf-max-bitrate">Bitrate</th>
					<th id="thf-dimensions">Dimensions</th>
					<th id="thf-type">Type</th>
					<th id="thf-delete">&nbsp;</th>
				</tr>
			</thead>
			<tbody>
				<tr py:for="file in media.files" py:strip="">
					${file_edit_form(file=file, action=file_edit_action)}
				</tr>
			</tbody>
		</table>
		<div class="box-content rounded-inputs clearfix">
			<div id="add-box" py:content="file_add_form(action=file_add_action)" />
		</div>
		<div class="box-bottom" />
	</div>
</div>

</body>
</html>
